///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#ifndef __GBUFFER_H__
#define __GBUFFER_H__

#include <MGLib.h>

#define		MAX_RES		(4096)
//#define		FAST

class GBuffer
{
public:

						GBuffer();
						~GBuffer();

	void				init(GLuint width, GLuint height, GLuint texCount, GLboolean depth, GLboolean stencil);

	void				create();
	void				destroy();

	GLuint				getColorTextureId( GLuint texCount );
	GLuint				getDepthTextureId();
	GLuint				getStencilTextureId();

	void				generateMipMaps();

	void				begin();
	void				end( GLuint ti = 0 );

	void				bindTextures();
	void				bindTexture(GLenum texTarget, GLuint texIndex = 0);
	void				bindDepthTexture(GLenum texTarget);
	void				bindStencilTexture(GLenum texTarget);

	//void				useFBO(GLboolean use)	{	m_bUseFBO = use;	}
	GLboolean			isUsingFBO()	{	return m_bUseFBO;	}

private:

	void				printFramebufferInfo();
	bool				checkFramebufferStatus();
	std::string			getTextureParameters(GLuint id);
	std::string			getRenderbufferParameters(GLuint id);
	std::string			convertInternalFormatToString(GLenum format);

	GLboolean			m_inited;

	GLboolean			m_bUseFBO;

	GLsizei				m_width;
	GLsizei				m_height;

	GLuint				m_fboId;
	GLuint				m_rboId;

	GLuint				m_texCount;
	GLuint				*m_tex;
	GLenum				*m_mrt;

	GLboolean			m_bDepth;
	GLuint				m_texDepth;
	GLboolean			m_bStencil;
	GLuint				m_texStencil;

};

#endif
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////